function set_localStorage_class(cookiename){  
       this.cookiename=cookiename;  //需要操作的cookie名
       this.AddOne=set_localStorage_class_add_one;          //向cookie添加一条记录
       this.DelAll=set_localStorage_class_del_all;          //删除所有cookie
       this.DelOne=set_localStorage_class_del_one;          //删除指定的cookie
       this.AddAll=set_localStorage_class_add_all;          //添加多条记录到cookie
       this.setCookie=function(value, expiredays){          //写入 或者 删除cookie    setCookie(cookiename,_db,1);  setCookie(cookiename,"",-10);
	        if(expiredays < 0){
	            localStorage.removeItem(this.cookiename);
	        }
          	localStorage.setItem(this.cookiename,value); 
	   };    
       this.getCookie=function(){                           //读取cookie    getCookie(cookiename);
			return  localStorage.getItem(this.cookiename);
	   }; 
       this.isExist =  function (ary,val,Only_sign){                  //判断json数据中是否存在商品编号id
				      var flg=false;
				      if(ary==null || ary.length==0)return flg;
				      for(var i=0;i<ary.length;i++){
				          if(ary[i][Only_sign]==val){
				              flg=true;
				              break;
				          }
				      }
				      return flg;
	   }  

	   this.CookieJsonChangeObj = function(){              //读取cookie 将json转换成obj
			 var ojson  =[]; 
			   var cookie_list =  this.getCookie();
			       if(cookie_list !=null && cookie_list!=""&& cookie_list!=undefined ){
			        ojson=JSON.parse(cookie_list);
			      }
			      return ojson;
		}		      
};  
 var set_localStorage_class_add_one=function(data,Only_sign){     //data 要添加的内容，要匹配的唯一标示
 	   var ojson =  [],ojsona =[];
	   ojson = this.CookieJsonChangeObj();
	   if(ojson.length >0){
		   var flag = this.isExist(ojson,data[Only_sign],Only_sign);
		   if(!flag ){ojson.push(data);}else{return '这条记录已近存在啦';}
		   var _json=JSON.stringify(ojson);
		   this.DelAll;
	   }else{
	   	ojsona.push(data);
	   	var _json=JSON.stringify(ojsona);
	   }
	   this.setCookie(_json,1);
	   return 1;
}; 
 var set_localStorage_class_del_all=function(){                //删除cookie
  this.setCookie('',-10);
  return 1;
}; 
 var set_localStorage_class_del_one=function(data,Only_sign){    //删除某条记录
    var ojson=[],lsjson=[],del_json=[];
	ojson = this.CookieJsonChangeObj();
    for(var i=0;i<ojson.length;i++){
        if(ojson[i][Only_sign] == data[Only_sign]){
            del_json.push(data);  //删除的
        }else{
            lsjson.push(ojson[i]); //剩余的
        }
    }
    if(lsjson.length>0){
        this.DelAll();
        var _db=JSON.stringify(lsjson);
        this.setCookie(_db,1);
        return 1;
    }else{
        if(del_json.length>0){
            this.DelAll();
            return 1;
        }
    } 
}; 
 var set_localStorage_class_add_all=function(data,Only_sign){ 
	 	var _obj =[]; 
	   	_obj = JSON.parse(data);
	    for(var i=0;i<_obj.length;i++){
	        this.AddOne(_obj[i],Only_sign);
	    }
	  return 1;
}; 




 // var  x =new  set_localStorage_class('daily_purchase_goods');  
 // x.setCookie('[{"GoodsSn":"TEST666dan","GoodsPrice":"8.4","Quantity":"1"},{"GoodsSn":"a1234","GoodsPrice":"84","Quantity":"1"}]',1);  //设置多条	
 //x.DelAll();   //删除所有
 // console.log(x.AddOne({"GoodsSn":"TEST666bbaa","GoodsPrice":"111","Quantity":"1"},'GoodsSn')); //新增一条
 // x.DelOne({"GoodsSn":"TEST666dan","GoodsPrice":"111","Quantity":"1"},'GoodsSn');  //删除一条
 // x.AddAll('[{"GoodsSn":"TEST666dan","GoodsPrice":"8.4","Quantity":"1"},{"GoodsSn":"a1234","GoodsPrice":"84","Quantity":"1"}]','GoodsSn');
 // console.log(x.getCookie());